package com.qiankun.tang.ui.fragment.find;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.common.library.listener.OnAppListener;
import com.common.library.tools.Logger;
import com.common.library.ui.fragment.BaseRecyclerFragment;
import com.qiankun.tang.R;
import com.qiankun.tang.beans.AuthorBean;
import com.qiankun.tang.beans.VideoSynopsisBean;
import com.qiankun.tang.beans.items.AuthorItem;
import com.qiankun.tang.beans.items.ClassifyItem;
import com.qiankun.tang.ui.activity.PlayerActivity;
import com.qiankun.tang.ui.view.adapter.find.AuthorAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author txf
 * @Title
 * @package com.qiankun.video.ui.fragment.find
 * @date 2017/6/13 0013
 */
public class AuthorFragment extends BaseRecyclerFragment<AuthorItem> implements OnAppListener.OnInteractionListener {

    List<String> lurls = new ArrayList<>();
    List<String> ltitles = new ArrayList<>();

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setAdapter(new AuthorAdapter(getContext(), this));
        initData();
    }
    private void initData() {
        //列表图片数据
        lurls = new ArrayList<>();
        String lurl1 = "res:///" + R.drawable.hom_list_1;
        String lurl2 = "res:///" + R.drawable.hom_list_2;
        String lurl3 = "res:///" + R.drawable.hom_list_3;
        String lurl4 = "res:///" + R.drawable.hom_list_4;
        String lurl5 = "res:///" + R.drawable.hom_list_5;
        String lurl6 = "res:///" + R.drawable.hom_list_6;
        String lurl7 = "res:///" + R.drawable.hom_list_7;
        String lurl8 = "res:///" + R.drawable.hom_list_8;
        String lurl9 = "res:///" + R.drawable.hom_list_9;
        String lurl10 = "res:///" + R.drawable.hom_list_10;
        lurls.add(lurl1);
        lurls.add(lurl2);
        lurls.add(lurl3);
        lurls.add(lurl4);
        lurls.add(lurl5);
        lurls.add(lurl6);
        lurls.add(lurl7);
        lurls.add(lurl8);
        lurls.add(lurl9);
        lurls.add(lurl10);
        ltitles = new ArrayList<>();
        String ltitle1 = "宝宝第一次滑雪是什么反应";
        String ltitle2 = "超美沙画作品-大话西游";
        String ltitle3 = "还有叫“嗡”的和弦";
        String ltitle4 = "巨好听！电吉他演绎张国荣经典";
        String ltitle5 = "另类日料，你吃得下吗";
        String ltitle6 = "美女可不是这么追的";
        String ltitle7 = "你躲得开我的凝视吗";
        String ltitle8 = "女神要这样撩";
        String ltitle9 = "悬崖速降，惊心动魄";
        String ltitle10 = "这么懒又这么萌的猫咪我要了";
        ltitles.add(ltitle1);
        ltitles.add(ltitle2);
        ltitles.add(ltitle3);
        ltitles.add(ltitle4);
        ltitles.add(ltitle5);
        ltitles.add(ltitle6);
        ltitles.add(ltitle7);
        ltitles.add(ltitle8);
        ltitles.add(ltitle9);
        ltitles.add(ltitle10);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }
    @Override
    protected void request(int pageIndex) {
        List<AuthorItem> items = buildHomeItems();
        refreshData(items);
    }

    private List<AuthorItem> buildHomeItems() {
        List<AuthorItem> items = new ArrayList<>();

        items.add(new AuthorItem(AuthorItem.TYPE_0,"热 门 作 者"));
        //作者
        for (int i = 0; i < 3 ; i++) {
            AuthorBean bean = new AuthorBean();
            bean.setId(i+"");
            bean.setIconUrl("res:///" + R.drawable.icon_deft_bg);
            if(i == 0){
                bean.setTitle("搞笑精彩片段");
                bean.setSubtitle("这里是搞笑短片的精选");
            }
            if(i == 1){
                bean.setTitle("音乐锦集");
                bean.setSubtitle("聆听新歌热歌的首选");
            }
            if(i == 2){
                bean.setTitle("诚实的预告片");
                bean.setSubtitle("[ 诚实的预告片 ] 中文字幕帐号");
            }
            items.add(new AuthorItem(AuthorItem.TYPE_1,bean));
        }

        items.add(new AuthorItem(AuthorItem.TYPE_0,"最 新 更 新 作 者"));
        //列表图片
        List<VideoSynopsisBean> videoSynopsisBeans1 = new ArrayList<>();
        for (int i = 1; i < 5; i++) {
            VideoSynopsisBean bean = new VideoSynopsisBean();
            bean.setImgUrl(lurls.get(i));
            bean.setSubtitle(ltitles.get(i));
            bean.setTitle(ltitles.get(i));
            videoSynopsisBeans1.add(bean);
        }
        List<VideoSynopsisBean> videoSynopsisBeans2 = new ArrayList<>();
        for (int i = 5; i < 10; i++) {
            VideoSynopsisBean bean = new VideoSynopsisBean();
            bean.setImgUrl(lurls.get(i));
            bean.setSubtitle(ltitles.get(i));
            bean.setTitle(ltitles.get(i));
            videoSynopsisBeans2.add(bean);
        }
        for (int i = 0; i < 3 ; i++) {
            AuthorBean bean = new AuthorBean();
            bean.setId(i+"");
            bean.setIconUrl("res:///" + R.drawable.icon_deft_bg);
            if(i == 0){
                bean.setTitle("搞笑精彩片段");
                bean.setSubtitle("这里是搞笑短片的精选");
                bean.setList(videoSynopsisBeans1);
            }
            if(i == 1){
                bean.setTitle("音乐锦集");
                bean.setSubtitle("聆听新歌热歌的首选");
                bean.setList(videoSynopsisBeans2);
            }
            if(i == 2){
                bean.setTitle("诚实的预告片");
                bean.setSubtitle("[ 诚实的预告片 ] 中文字幕帐号");
                bean.setList(videoSynopsisBeans1);
            }
            items.add(new AuthorItem(AuthorItem.TYPE_2,bean));
        }
        return items;
    }
    private void startPlayerActivity(String id){
        startActivity(PlayerActivity.newIntent(id,getActivity()));
        getActivity().overridePendingTransition(R.anim.activity_zoomin,R.anim.activity_zoomout);
    }
    @Override
    public void onInteraction(int type, Object o) {
        switch (type) {
            case ClassifyItem.TYPE_0:
                Logger.i("点击Item 类型为 0");
                break;
            case ClassifyItem.TYPE_1:
                Logger.i("点击Item 类型为 1");
//                startPlayerActivity("1");
                break;
            case ClassifyItem.TYPE_2:
                Logger.i("点击Item 类型为 2");
                startPlayerActivity("2");
                break;
        }
    }
}
